const app = getApp();

Component({
  properties:{
    isbackground:{
      type:Boolean,
      value:false,
    },
    url:{
      type:String,
      value:'',
      observer:function(newVal,oldVal){
        if(newVal != oldVal){

        }
      }
    },
    width:{
      type:String,
      value:"200"
    },
    height:{
      type:String,
      value:"200"
    }
  },
  data:{
    imgWidth:0,
    imgHeight:0
  },
  attached(){

  },
  methods:{
    imgLoad(e){
      var _thisInfo = e.detail;
      var { width, height, imgWidth,imgHeight} = this.data;
      var _proportion = _thisInfo.width / _thisInfo.height;
      if(width < height){
        imgHeight = height;
        imgWidth = Math.ceil(_proportion * height);
      }else if(width > height){
        imgWidth = width;
        imgHeight = Math.ceil(width / _proportion);
      }else{
        if(width > height){
          imgWidth = width;
          imgHeight = width;
        }else{
          imgWidth = height;
          imgHeight = height;
        }
      }

      this.setData({
        imgWidth:imgWidth,
        imgHeight:imgHeight
      })
    },
    imgError(){
      var { width, height, imgWidth, imgHeight } = this.data;
      if (width > height) {
        imgWidth = width;
        imgHeight = width;
      } else {
        imgWidth = height;
        imgHeight = height;
      }
      this.setData({
        url:'/utils/images/noimg.jpg',
        imgWidth:imgWidth,
        imgHeight:imgHeight
      })
    }
  }
})